package top.infopub.job.util;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


public class OAUtil {
    public static void main(String[] args) throws IOException {
        Map<String,String> oaMap=new HashMap<>();
        oaMap.put("titile","待办单点登录测试1");
        oaMap.put("createbyname","王文波");
        oaMap.put("createbycode","1937694");
        oaMap.put("toname","王文波");
        oaMap.put("tocode","1937694");
        oaMap.put("type","znjt");
        oaMap.put("url","http://39.99.211.193:8088/mgr/mgr/sso?date="+System.currentTimeMillis()+"&backUrl=http://39.99.211.193:8088/mgr/flow/list");//处理公文页面链接
        oaMap.put("company","江苏中南建设集团");//公司名称
        //String url = "http://proxy.zhongnangroup.cn/znapicloud/api/jingshi/erp/todo";
        //String s = JSONUtils.toJSONString(oaMap);
        JSONObject jsonObject = erpTodo(oaMap);
       // String post = HttpUtils.post(url, s);
        //JSONObject str = JSONObject.parseObject(post);
        System.out.println(jsonObject);
        //JSONObject str = OAUtil.inserterpoa(oaMap);
        boolean success = jsonObject.getBoolean("success");
        String oaId = "";
        if(success){
            oaId = jsonObject.getString("id");
            System.out.println(oaId);
        }else{
//            throw new FlowProcessException("发起OA待办失败，请联系管理员");
        }
        //19c8281cd74a3facd7c6258406bd6750  1426463be9fccf75ddcf3ee5a6a5c19e
        //finishOA("bb8f863626c16bc1084cee482c90023d");
        //finishOA("19c8281cd74a3facd7c6258406bd6750");

        /*String url2 = "http://proxy.zhongnangroup.cn/znapicloud/api/jingshi/erp/finish";
        String get = HttpUtils.sendGet(url2, "id=477441e03d80747f5c832011d0c0f290");
        JSONObject str2 = JSONObject.parseObject(get);
        System.out.println(get);
        boolean success2 = str2.getBoolean("success");
        if(success2){
            System.out.println("成功");
        }*/
       /* String encode = MD5.encode("wangwenbo" + "**X7&2K$O@7XH" + "Znjt123456");
        System.out.println(encode);*/
    }
    public static JSONObject erpTodo(Map<String,String> oaMap)  {
        // 要调用的接口方法
        String url = "http://proxy.zhongnangroup.cn/znapicloud/api/jingshi/erp/todo";
        String s = JSONUtils.toJSONString(oaMap);
        String post = null;
//        try {
//            post = HttpUtils.post(url, s);
            post = HttpClientUtil.postJson(url, s);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        JSONObject str = JSONObject.parseObject(post);
        return str;
    }


    public static JSONObject finishOA(String id) {
//        HttpClient client = HttpClients.createDefault();
        // 要调用的接口方法
        String url = "http://proxy.zhongnangroup.cn/znapicloud/api/jingshi/erp/finish?id=" + id;
        String get = HttpClientUtil.httpClientGet(url);
        JSONObject str = JSONObject.parseObject(get);
        /*boolean success2 = str.getBoolean("success");
        if(success2){
            System.out.println("成功");
        }*/
        return str;
    }
}
